/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef __C_ANIM_BILLBOARD_SCENE_NODE_H_INCLUDED__
#define __C_ANIM_BILLBOARD_SCENE_NODE_H_INCLUDED__

#include "ISceneNode.h"
#include "Lib2D/Sprite.h"
#include "Lib2D/SpriteInstance.h"
#include "CBillboardSceneNode.h"

//! Scene node which is a billboard using 2d sprite
//! which always looks to the camera. 
class AnimBillboardSceneNode : public irr::scene::CBillboardSceneNode
{
public:

	// id for my scene node
    static const int ANIMATED_BILLBOARD_SCENE_NODE_ID = MAKE_IRR_ID('a','b','i','l');

	//! constructor
	AnimBillboardSceneNode(irr::scene::ISceneNode* parent, irr::scene::ISceneManager* mgr, irr::s32 id = -1);
	~AnimBillboardSceneNode();

	virtual void OnRegisterSceneNode();

	//! renders the node.
	virtual void render(void* renderData = 0);

	void update(float timeStamp);

	//! returns the axis aligned bounding box of this node
	virtual const irr::core::aabbox3d<irr::f32>& getBoundingBox() const;

	//! sets the size of the billboard
	virtual void setSize(const irr::f32 size);

	//! gets the size of the billboard
	//virtual const irr::f32 getSize() const;

	//! Returns type of the scene node
	virtual irr::scene::ESCENE_NODE_TYPE getType() const { return (irr::scene::ESCENE_NODE_TYPE)ANIMATED_BILLBOARD_SCENE_NODE_ID; }

	//! loads the sprite to render
	void LoadSprite(const char* spriteName);

	//! unload sprite res, useful for reuse in pool
	void UnloadSprite();

	void SetAnim(irr::s32 id)	{ if(m_spriteInstance) m_spriteInstance->SetAnim(id); };
	bool IsAnimEnded()			{ return m_spriteInstance ? m_spriteInstance->IsAnimEnded() : true;}

	int GetAnimCount()
	{
		if(m_sprite)
		{
			return m_sprite->GetNoAnims();
		}

		return 0;
	}

	void SetBillboardMaterialType(irr::video::E_MATERIAL_TYPE type);

	virtual void OnMaterialChanged();
	virtual irr::u32 getMaterialCount () const;
	virtual irr::video::SMaterial& getMaterial (irr::u32 num);

	AnimBillboardSceneNode* clone ();

	CSprite* m_sprite;
	CSpriteInstance* m_spriteInstance;

private:

	irr::f32 Size;
	irr::core::aabbox3d<irr::f32> BBox;
	irr::core::stringc m_spritename;

	float m_fLastTimeStamp;
};

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#endif // __C_ANIM_BILLBOARD_SCENE_NODE_H_INCLUDED__

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
